package com.springboot.learn_sofa_rpc_client;

import com.alipay.sofa.rpc.config.ConsumerConfig;
import com.springboot.IRpcService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class RpcHander {
    ConsumerConfig<IRpcService> consumerConfig;
    @Value("${rpc.ip}")
    private String rpc_ip;
    @Value("${rpc.port}")
    private int rpc_port;
    @Value("${rpc.protocol}")
    private String rpc_protocol = "bolt";
    public void init(){
        if(consumerConfig == null){
            consumerConfig = new ConsumerConfig<IRpcService>()
                    .setInterfaceId(IRpcService.class.getName())//指定接口
                    .setProtocol(rpc_protocol)//指定协议
                    .setDirectUrl(rpc_protocol+"://"+rpc_ip+":"+rpc_port);//指定直连地址
        }
    }
    public ConsumerConfig getConsumer(){
        init();
        return consumerConfig;
    }
}
